#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define in read()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

const int N = 1e5 + 10;

int dep[N], n, Q;
vec G[N];

namespace T {
	const int N = 2e5 + 10;
	const int K = 18;
	int pot[N], L[N], R[N], tot, dep[N], f[K + 1][N], lg[N];
	int tmin(int x, int y) { return dep[x] < dep[y] ? x : y; } 
	void dfs(int x, int p) {
		pot[L[x] = R[x] = ++tot] = x; dep[x] = dep[p] + 1;
		for(auto y : G[x]) if(y ^ p) dfs(y, x), pot[R[x] = ++tot] = x;
	}
	void init() {
		dfs(1, 0);
		rep(i, 1, tot) f[0][i] = pot[i];
		rep(i, 1, K)
			rep(j, 1, tot)
			f[i][j] = tmin(f[i - 1][j], f[i - 1][j + (1 << i - 1)]);
		rep(i, 2, tot) lg[i] = lg[i >> 1] + 1;
	}
	int lca(int x, int y) { if(L[x] > L[y]) swap(x, y); x = L[x]; y = R[y]; int k = lg[y - x + 1]; return tmin(f[k][x], f[k][y - (1 << k) + 1]); }
	int dis(int x, int y) { return x == -1 || y == -1 ? -1 : dep[x] + dep[y] - 2 * dep[lca(x, y)]; }
}

namespace seg {
	pii val[N << 1];
	int ch[N << 1][2], L[N << 1], R[N << 1], rt, ndn, md[N << 1];
	pii operator + (pii a, pii b) {
		pii c = { -1, -1 }; int res = -1, cur = 0;
		if((cur = T :: dis(a.fi, a.se)) >= res) res = cur, c = { a.fi, a.se };
		if((cur = T :: dis(a.fi, b.fi)) >= res) res = cur, c = { a.fi, b.fi };
		if((cur = T :: dis(a.fi, b.se)) >= res) res = cur, c = { a.fi, b.se };
		if((cur = T :: dis(a.se, b.fi)) >= res) res = cur, c = { a.se, b.fi };
		if((cur = T :: dis(a.se, b.se)) >= res) res = cur, c = { a.se, b.se };
		if((cur = T :: dis(b.fi, b.se)) >= res) res = cur, c = { b.fi, b.se };
		return c;
	}
	void build(int &o, int l, int r) {
		o = ++ndn; L[o] = l; R[o] = r; if(l == r) return val[o] = { l, l }, void(); md[o] = (l + r) >> 1;
		build(ch[o][0], l, md[o]); build(ch[o][1], md[o] + 1, r); val[o] = val[ch[o][0]] + val[ch[o][1]];
	}
	int pos;
	void upd(const int &o) {
		if(L[o] == R[o]) return val[o] = (val[o] == pii(-1, -1) ? pii(L[o], L[o]) : pii(-1, -1)), void();
		if(pos <= md[o]) upd(ch[o][0]); else upd(ch[o][1]); val[o] = val[ch[o][0]] + val[ch[o][1]];
	}
	void tpd(const int &p) { pos = p; upd(rt); }
	void init() { build(rt, 1, n); }
	pii get() { return val[rt]; }
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in; rep(i, 2, n) { int u = in, v = in; G[u].eb(v); G[v].eb(u); }
	T :: init(); seg :: init();
	Q = in;
	while(Q--) {
		char ch = getchar(); while(!isalpha(ch)) ch = getchar();
		if(ch == 'C') seg :: tpd(in);
		else { auto p = seg :: get(); printf("%d\n", T :: dis(p.fi, p.se)); }
	}
	return 0;
}
